home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / AIncludes / fenv.a < prev    next >
Encoding:
Text File  |  1998-02-12  |  11.8 KB  |  325 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        fenv.a
  3. ;
  4. ;    Contains:    Floating-Point environment for PowerPC and 68K
  5. ;
  6. ;    Version:    Technology:    MathLib v2
  7. ;                Release:    Universal Interfaces 3.1
  8. ;
  9. ;    Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10. ;
  11. ;    Bugs?:        Please include the the file and version information (from above) with
  12. ;                the problem description.  Developers belonging to one of the Apple
  13. ;                developer programs can submit bug reports to:
  14. ;
  15. ;                    devsupport@apple.com
  16. ;
  17. ;
  18.     IF &TYPE('__FENV__') = 'UNDEFINED' THEN
  19. __FENV__ SET 1
  20.  
  21.     IF &TYPE('__CONDITIONALMACROS__') = 'UNDEFINED' THEN
  22.     include 'ConditionalMacros.a'
  23.     ENDIF
  24.  
  25.     IF TARGET_OS_MAC THEN
  26. ;    A collection of functions designed to provide access to the floating
  27. ;    point environment for numerical programming. It is modeled after
  28. ;    the floating-point requirements in C9X.
  29. ;    
  30. ;    The file <fenv.h> declares many functions in support of numerical
  31. ;    programming.  It provides a set of environmental controls similar to
  32. ;    the ones found in <SANE.h>.  Programs that test flags or run under
  33. ;    non-default modes must do so under the effect of an enabling
  34. ;    "fenv_access" pragma.
  35. ;
  36.  
  37.  
  38. ; ********************************************************************************
  39. ;*                                                                                *
  40. ;*    fenv_t         is a type for representing the entire floating-point        *
  41. ;*                     environment in a single object.                              *
  42. ;*                                                                                *
  43. ;*     fexcept_t        is a type for representing the floating-point                *
  44. ;*                     exception flag state collectively.                           *
  45. ;*                                                                                *
  46. ;*******************************************************************************
  47.  
  48.     IF TARGET_CPU_PPC THEN
  49. ; typedef long                             fenv_t
  50.  
  51. ; typedef long                             fexcept_t
  52.  
  53. ;     Definitions of floating-point exception macros                          
  54.  
  55. FE_INEXACT                        EQU        $02000000
  56. FE_DIVBYZERO                    EQU        $04000000
  57. FE_UNDERFLOW                    EQU        $08000000
  58. FE_OVERFLOW                        EQU        $10000000
  59. FE_INVALID                        EQU        $20000000
  60.  
  61. ;     Definitions of rounding direction macros                                
  62.  
  63. FE_TONEAREST                    EQU        $00000000
  64. FE_TOWARDZERO                    EQU        $00000001
  65. FE_UPWARD                        EQU        $00000002
  66. FE_DOWNWARD                        EQU        $00000003
  67.     ENDIF    ; TARGET_CPU_PPC
  68.     IF TARGET_CPU_68K THEN
  69.     IF TARGET_RT_MAC_68881 THEN
  70. ; typedef long                             fexcept_t
  71.  
  72. fenv_t                    RECORD 0
  73. FPCR                     ds.l    1                ; offset: $0 (0)
  74. FPSR                     ds.l    1                ; offset: $4 (4)
  75. sizeof                     EQU *                    ; size:   $8 (8)
  76.                         ENDR
  77.  
  78. FE_INEXACT                        EQU        $00000008            ; ((long)(8))   
  79. FE_DIVBYZERO                    EQU        $00000010            ; ((long)(16))  
  80. FE_UNDERFLOW                    EQU        $00000020            ; ((long)(32))  
  81. FE_OVERFLOW                        EQU        $00000040            ; ((long)(64))  
  82. FE_INVALID                        EQU        $00000080            ; ((long)(128)) 
  83.     ELSE
  84. ; typedef short                         fexcept_t
  85.  
  86. ; typedef short                         fenv_t
  87.  
  88.  
  89. FE_INVALID                        EQU        $0001                ; ((short)(1))  
  90. FE_UNDERFLOW                    EQU        $0002                ; ((short)(2))  
  91. FE_OVERFLOW                        EQU        $0004                ; ((short)(4))  
  92. FE_DIVBYZERO                    EQU        $0008                ; ((short)(8))  
  93. FE_INEXACT                        EQU        $0010                ; ((short)(16)) 
  94.     ENDIF    ; TARGET_RT_MAC_68881
  95.  
  96. FE_TONEAREST                    EQU        $0000                ; ((short)(0))  
  97. FE_UPWARD                        EQU        $0001                ; ((short)(1))  
  98. FE_DOWNWARD                        EQU        $0002                ; ((short)(2))  
  99. FE_TOWARDZERO                    EQU        $0003                ; ((short)(3))  
  100. ;     Definitions of rounding precision macros  (68K only)                    
  101.  
  102. FE_LDBLPREC                        EQU        $0000                ; ((short)(0))  
  103. FE_DBLPREC                        EQU        $0001                ; ((short)(1))  
  104. FE_FLTPREC                        EQU        $0002                ; ((short)(2))  
  105.     ENDIF    ; TARGET_CPU_68K
  106. ;     The bitwise OR of all exception macros                                  
  107. ; *******************************************************************************
  108. ;*     The following functions provide access to the exception flags.  The      *
  109. ;*     "int" input argument can be constructed by bitwise ORs of the exception  *
  110. ;*     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  111. ;******************************************************************************
  112.  
  113. ; *******************************************************************************
  114. ;*     The function "feclearexcept" clears the supported exceptions represented *
  115. ;*     by its argument.                                                         *
  116. ;******************************************************************************
  117.  
  118. ;
  119. ; extern void feclearexcept(int excepts)
  120. ;
  121.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  122.         IMPORT_CFM_FUNCTION feclearexcept
  123.     ENDIF
  124.  
  125.  
  126.  
  127. ; *******************************************************************************
  128. ;*    The function "fegetexcept" stores a representation of the exception       *
  129. ;*     flags indicated by the argument "excepts" through the pointer argument   *
  130. ;*     "flagp".                                                                 *
  131. ;******************************************************************************
  132.  
  133. ;
  134. ; extern void fegetexcept(fexcept_t *flagp, int excepts)
  135. ;
  136.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  137.         IMPORT_CFM_FUNCTION fegetexcept
  138.     ENDIF
  139.  
  140.  
  141.  
  142. ; *******************************************************************************
  143. ;*     The function "feraiseexcept" raises the supported exceptions             *
  144. ;*     represented by its argument.                                             *
  145. ;******************************************************************************
  146.  
  147. ;
  148. ; extern void feraiseexcept(int excepts)
  149. ;
  150.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  151.         IMPORT_CFM_FUNCTION feraiseexcept
  152.     ENDIF
  153.  
  154.  
  155.  
  156. ; *******************************************************************************
  157. ;*     The function "fesetexcept" sets or clears the exception flags indicated  *
  158. ;*     by the int argument "excepts" according to the representation in the     *
  159. ;*     object pointed to by the pointer argument "flagp".  The value of         *
  160. ;*     "*flagp" must have been set by a previous call to "fegetexcept".         *
  161. ;*     This function does not raise exceptions; it just sets the state of       *
  162. ;*     the flags.                                                               *
  163. ;******************************************************************************
  164.  
  165. ;
  166. ; extern void fesetexcept(const fexcept_t *flagp, int excepts)
  167. ;
  168.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  169.         IMPORT_CFM_FUNCTION fesetexcept
  170.     ENDIF
  171.  
  172.  
  173.  
  174. ; *******************************************************************************
  175. ;*     The function "fetestexcept" determines which of the specified subset of  *
  176. ;*     the exception flags are currently set.  The argument "excepts" specifies *
  177. ;*     the exception flags to be queried as a bitwise OR of the exception       *
  178. ;*     macros.  This function returns the bitwise OR of the exception macros    *
  179. ;*     corresponding to the currently set exceptions included in "excepts".     *
  180. ;******************************************************************************
  181.  
  182. ;
  183. ; extern int fetestexcept(int excepts)
  184. ;
  185.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  186.         IMPORT_CFM_FUNCTION fetestexcept
  187.     ENDIF
  188.  
  189.  
  190.  
  191. ; *******************************************************************************
  192. ;*     The following functions provide control of rounding direction modes.     *
  193. ;******************************************************************************
  194.  
  195. ; *******************************************************************************
  196. ;*     The function "fegetround" returns the value of the rounding direction    *
  197. ;*     macro which represents the current rounding direction.                   *
  198. ;******************************************************************************
  199.  
  200. ;
  201. ; extern int fegetround(void )
  202. ;
  203.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  204.         IMPORT_CFM_FUNCTION fegetround
  205.     ENDIF
  206.  
  207.  
  208.  
  209. ; *******************************************************************************
  210. ;*     The function "fesetround" establishes the rounding direction represented *
  211. ;*     by its argument.  It returns nonzero if and only if the argument matches *
  212. ;*     a rounding direction macro.  If not, the rounding direction is not       *
  213. ;*     changed.                                                                 *
  214. ;******************************************************************************
  215.  
  216. ;
  217. ; extern int fesetround(int round)
  218. ;
  219.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  220.         IMPORT_CFM_FUNCTION fesetround
  221.     ENDIF
  222.  
  223.  
  224.  
  225. ; *******************************************************************************
  226. ;*    The following functions manage the floating-point environment, exception  *
  227. ;*    flags and dynamic modes, as one entity.                                   *
  228. ;******************************************************************************
  229.  
  230. ; *******************************************************************************
  231. ;*     The function "fegetenv" stores the current floating-point environment    *
  232. ;*     in the object pointed to by its pointer argument "envp".                 *
  233. ;******************************************************************************
  234.  
  235. ;
  236. ; extern void fegetenv(fenv_t *envp)
  237. ;
  238.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  239.         IMPORT_CFM_FUNCTION fegetenv
  240.     ENDIF
  241.  
  242.  
  243.  
  244. ; *******************************************************************************
  245. ;*     The function "feholdexcept" saves the current environment in the object  *
  246. ;*     pointed to by its pointer argument "envp", clears the exception flags,   *
  247. ;*     and clears floating-point exception enables.  This function supersedes   *
  248. ;*     the SANE function "procentry", but it does not change the current        *
  249. ;*     rounding direction mode.                                                 *
  250. ;******************************************************************************
  251.  
  252. ;
  253. ; extern int feholdexcept(fenv_t *envp)
  254. ;
  255.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  256.         IMPORT_CFM_FUNCTION feholdexcept
  257.     ENDIF
  258.  
  259.  
  260.  
  261. ; *******************************************************************************
  262. ;*     The function "fesetenv" installs the floating-point environment          *
  263. ;*     environment represented by the object pointed to by its argument         *
  264. ;*     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  265. ;*     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  266. ;*     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  267. ;******************************************************************************
  268.  
  269. ;
  270. ; extern void fesetenv(const fenv_t *envp)
  271. ;
  272.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  273.         IMPORT_CFM_FUNCTION fesetenv
  274.     ENDIF
  275.  
  276.  
  277.  
  278. ; *******************************************************************************
  279. ;*     The function "feupdateenv" saves the current exceptions into its         *
  280. ;*     automatic storage, installs the environment represented through its      *
  281. ;*     pointer argument "envp", and then re-raises the saved exceptions.        *
  282. ;*     This function, which supersedes the SANE function "procexit", can be     *
  283. ;*     used in conjunction with "feholdexcept" to write routines which hide     *
  284. ;*     spurious exceptions from their callers.                                  *
  285. ;******************************************************************************
  286.  
  287. ;
  288. ; extern void feupdateenv(const fenv_t *envp)
  289. ;
  290.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  291.         IMPORT_CFM_FUNCTION feupdateenv
  292.     ENDIF
  293.  
  294.  
  295.  
  296.     IF TARGET_CPU_68K THEN
  297. ; *******************************************************************************
  298. ;*     The following functions provide control of rounding precision.           *
  299. ;*     Because the PowerPC does not provide this capability, these functions    *  
  300. ;*     are available only for the 68K Macintosh.  Rounding precision values     *
  301. ;*     are defined by the rounding precision macros.  These functions are       *
  302. ;*     equivalent to the SANE functions getprecision and setprecision.          *
  303. ;******************************************************************************
  304.  
  305. ;
  306. ; extern int fegetprec(void )
  307. ;
  308.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  309.         IMPORT_CFM_FUNCTION fegetprec
  310.     ENDIF
  311.  
  312. ;
  313. ; extern int fesetprec(int precision)
  314. ;
  315.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  316.         IMPORT_CFM_FUNCTION fesetprec
  317.     ENDIF
  318.  
  319.     ENDIF    ; TARGET_CPU_68K
  320.     ENDIF    ; TARGET_OS_MAC
  321.  
  322.     ENDIF ; __FENV__ 
  323.  
  324.